package com.siashan.toolkit.captcha.google;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.siashan.toolkit.captcha.core.CaptchaInfo;
import com.siashan.toolkit.captcha.core.ICaptcha;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * Google图形验证码
 *
 * @author siashan
 * @since v1.0.3
 **/
@Setter
@Getter
@NoArgsConstructor
public class GoogleCaptcha implements ICaptcha {

    /**
     * Google DefaultKaptcha 对象
     */
    private DefaultKaptcha kaptcha;

    /**
     * 验证码类型
     */
    private GoogleCaptchaType captchaType;


    public GoogleCaptcha(DefaultKaptcha kaptcha) {
        this.kaptcha = kaptcha;
    }

    public GoogleCaptcha(DefaultKaptcha kaptcha,GoogleCaptchaType captchaType) {
        this.kaptcha = kaptcha;
        this.captchaType = captchaType;
    }

    /**
     * 渲染
     */
    @Override
    public CaptchaInfo render() {
        return GoogleCaptchaUtil.render(kaptcha, captchaType).getCaptchaInfo();
    }
}
